<?php
/*========================================= JooSam =========================================/
/																							/
/	Extention:		JooSam																	/
/	Created by:		ScriptPlanet.eu															/
/	Site:			http://www.scriptplanet.eu												/
/	Email:			support@scriptplanet.eu													/
/	Support:		http://www.scriptplanet.eu/support										/
/	Copyright:		2011 (c) ScriptPlanet.eu												/
/	License:		CC BY-NC-ND 3.0 ~ http://creativecommons.org/licenses/by-nc-nd/3.0/		/
/	File Version:	0001																	/
/																							/
/========================================== JooSam ========================================*/
// Joomla Security
defined('_JEXEC') or die;
JHtml::addIncludePath(JPATH_COMPONENT.'/helpers/html');

JHtml::_('behavior.tooltip');
JHtml::_('behavior.formvalidation');
?>

<script type="text/javascript">
	Joomla.submitbutton = function(task)
	{
		if (task == 'textstring.cancel' || document.formvalidator.isValid(document.id('textstring-form'))) {
			Joomla.submitform(task, document.getElementById('textstring-form'));
		}
		else {alert("<?php echo JText::_('COM_JOOSAM_JSCRIPT_NOFIL'); ?>");}
		return false;
	}
</script>

<form action="<?php echo JRoute::_('index.php?option=com_joosam&layout=edit&id='.(int) $this->item->id); ?>" method="post" name="adminForm" id="textstring-form" class="form-validate">
<fieldset style="width:760px; margin:0 auto; border-radius:7px; background:#e6f2ff;">
	<table style="width:100%; padding-top:-1px;">
		<thead></thead>
		<tbody class="panelform">
			<?php foreach($this->form->getFieldset('samdata') as $field): ?>
				<tr class="panelform">
					<td id="TD_<?php echo $field->id; ?>_label" style="width:110px;"><?php echo $field->label; ?></td>
					<td id="TD_<?php echo $field->id; ?>_input" style="padding-top:2px;"><?php echo $field->input; ?></td>
				</tr>
			<?php endforeach; ?>
			<tr class="panelform" style="margin:2px 0 0 0;"><td colspan="2" style="margin:2px 0 0 0;"><hr style="margin:2px 0 0 0; color:#b2b2b2; border-color:white;"/></td></tr>
			<?php foreach($this->form->getFieldset('textdata') as $field): ?>
				<tr class="adminformlist" style="margin-top:0;">
					
						<td id="TD_<?php echo $field->id; ?>_label" style="width:110px; vertical-align:top; padding-top:6px; margin-right:-30px;"><?php echo $field->label; ?></td>
						<td id="TD_<?php echo $field->id; ?>_input" ><?php echo $field->input; ?></td>
					
				</tr>
			<?php endforeach; ?>
		</tbody>
		<tfoot></tfoot>
	</table>
</fieldset>
	<div>
		
			<?php foreach($this->form->getFieldset('hiddendata') as $field): ?>
				<?php echo $field->label;echo $field->input;?>
			<?php endforeach; ?>
		
		<input type="hidden" name="task" value="" />
		<?php echo JHtml::_('form.token'); ?>
	</div>
</form><br/>
<div class="clr"></div>
<!-- If you have respect for scriptplanet.eu you don't delete the code below -->
<div class="spCopyFooter" style="padding:0;margin:0 auto;font-size:9px;width:220px;text-align:center;"><span>JooSam created by</span><a href="http://www.scriptplanet.eu">ScriptPlanet.eu</a><a rel="license" href="http://creativecommons.org/licenses/by-nc-nd/3.0/"><img alt="Creative Commons Licentie" style="border-width:0" src="http://i.creativecommons.org/l/by-nc-nd/3.0/80x15.png" /></a></div>


<script type="text/javascript">
	var isdef = document.getElementById('jform_isdef').getAttribute("value");
	if(isdef=="true"){
		document.getElementById('jform_samerror').setAttribute('readonly','true');
		document.getElementById('jform_samerror').setAttribute('style','border:none;background:#E6F2FF;font-size:16px;font-weight:bold;color:#339900;');
		document.getElementById('jform_samerror').setAttribute('title',"<?php echo JText::_('COM_JOOSAM_VIEW_TXTSTRINGS_SCRIPT_NODEFCODE'); ?>");
		document.getElementById('jform_samerror-lbl').innerHTML = "<?php echo JText::_('COM_JOOSAM_VIEW_TXTSTRINGS_SCRIPT_SAMCODE'); ?>";
		document.getElementById('jform_txtstring').setAttribute("onkeypress", "return nospeckey(event)");
	}
	else{
		document.getElementById('jform_samerror').setAttribute("onkeypress", "return onlyNumbers(event)");
		document.getElementById('jform_txtstring').setAttribute("onkeyup", "return taCount('jform_txtstring')");
	}


function taCount(thisid){
	var target = document.getElementById(thisid);
	var tLength = target.value.length;
	var maxlength = 40;
	var illegalch = /[\<\>\{\}\#\;\\\^\/\"\'\[\]]/;
	var txtlength = "<?php echo JText::_('COM_JOOSAM_VIEW_TXTSTRINGS_SCRIPT_MAXCHAR'); ?>";

	if(tLength>maxlength){
		target.value=target.value.substring(0,maxlength);
		alert(txtlength);
	}
  
	var emtyLe = 0;
	while(emtyLe<tLength){
		var achar = target.value.charAt(emtyLe);
		
		if(illegalch.test(achar)){
			alert("<?php echo JText::_('COM_JOOSAM_VIEW_TXTSTRINGS_SCRIPT_BADCHAR'); ?>");
			
			var thval = target.value;
			var tail = thval.substring(emtyLe+1);
			target.value = thval.substring(0,emtyLe)+'*'+tail;
			tLength--;
		}
		else{
			emtyLe++;
		}
	}
}
function nospeckey(e){
	var keynum;
	var keychar;
	var numcheck;
	if(window.event){
		keynum = e.keyCode;
	}
	else if(e.which){
		keynum = e.which;
	}
	keychar = String.fromCharCode(keynum);
	numcheck = /[\<\>\#\;\\\^\/\"\'\[\]]/;
	if (keychar.match(numcheck)) {
		alert("<?php echo JText::_('COM_JOOSAM_VIEW_TXTSTRINGS_SCRIPT_BADCHAR'); ?>");
	}
	return !numcheck.test(keychar);
}
	
function onlyNumbers(e){
	var keynum;
	var keychar;
	var numcheck;

	if(window.event){
		keynum = e.keyCode;
	}
	else if(e.which){
		keynum = e.which;
	}
	keychar = String.fromCharCode(keynum);
	numcheck = /\d/;
	return numcheck.test(keychar);
}
</script>
